#!/bin/bash

echo "=== 测试分布式存储系统修复 ==="
echo ""

# 检查端口占用情况
echo "1. 检查端口占用情况："
echo "   chunkmaster应该使用50050端口"
echo "   chunkserver应该使用50051端口"
echo ""

# 启动chunkmaster
echo "2. 启动chunkmaster服务..."
cd /Users/zhangyi/git_space/build-a-distribute-storage/persistent_layer/chunkmaster/build
./chunkmaster &
CHUNKMASTER_PID=$!
sleep 2

# 启动chunkserver
echo "3. 启动chunkserver服务..."
cd /Users/zhangyi/git_space/build-a-distribute-storage/persistent_layer/chunkserver/build
./chunkserver_server &
CHUNKSERVER_PID=$!
sleep 2

# 启动chunkserver_client
echo "4. 启动chunkserver_client..."
cd /Users/zhangyi/git_space/build-a-distribute-storage/persistent_layer/chunkserver/build
./chunkserver_client &
CLIENT_PID=$!
sleep 2

echo ""
echo "=== 测试完成 ==="
echo "请手动测试以下功能："
echo "1. 在chunkmaster CLI中使用 'alloc chunk' 命令分配chunk"
echo "2. 在chunkserver_client CLI中使用 'allocate' 命令分配chunk"
echo "3. 比较两个chunk ID是否一致"
echo "4. 在chunkserver_client中使用 'show meta' 命令查看是否从chunkmaster获取最新信息"
echo "5. 检查端口配置是否正确"
echo ""
echo "按任意键停止所有服务..."
read -n 1

# 停止所有服务
echo ""
echo "停止所有服务..."
kill $CHUNKMASTER_PID 2>/dev/null
kill $CHUNKSERVER_PID 2>/dev/null
kill $CLIENT_PID 2>/dev/null
echo "测试完成" 